package com.smarthome.core.statisticsquery.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShAccountService;
import com.smarthome.base.service.ShAccountTypeService;
import com.smarthome.domain.enums.AccountStatus;
import com.smarthome.domain.enums.SexEnum;
import com.smarthome.common.tools.EnumUtil;
import com.smarthome.core.statisticsquery.OwenrStatisticsService;
import com.smarthome.domain.bean.ShAccount;
import com.smarthome.domain.bean.ShAccountType;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;
@Service("owenrStatisticsService")
public class OwenrStatisticsServiceImpl implements OwenrStatisticsService {

	
	protected static Logger LOGGER;
	
	@Resource
    private ShAccountService shAccountService;
	
	@Resource
	private ShAccountTypeService shAccountTypeService;
	
	@Override
	public DataGrid dataGrid(ShAccount account, PageHelper page) {
		return shAccountService.queryShAccounts(account, page);
	}

	@Override
	public List<Combobox> type(boolean flag) {
		List<Combobox> result = new ArrayList<>();
		if(flag) {
			Combobox combobox = new Combobox();
			combobox.setValue("");
			combobox.setText("--请选择--");
			combobox.setSelected(true);
			result.add(combobox);
		}
		List<ShAccountType> accountTypes = shAccountTypeService.queryList(new ShAccountType());
		for(ShAccountType type:accountTypes) {
			result.add(new Combobox(String.valueOf(type.getId()),type.getName()));
		}
		return result;
	}

	@Override
	public List<Combobox> sex(boolean flag) {
		List<Combobox> result = new ArrayList<>();
		if(flag) {
			Combobox combobox = new Combobox();
			combobox.setValue("");
			combobox.setText("--请选择--");
			combobox.setSelected(true);
			result.add(combobox);
		}
		List<SexEnum> sexEnum = EnumUtil.getEnumList(SexEnum.class);
		for(SexEnum sex:sexEnum) {
			result.add(new Combobox(String.valueOf(sex.getCode()),sex.getName()));
		}
		return result;
	}

	@Override
	public List<Combobox> status(boolean flag) {
		List<Combobox> result = new ArrayList<>();
		if(flag) {
			Combobox combobox = new Combobox();
			combobox.setValue("");
			combobox.setText("--请选择--");
			combobox.setSelected(true);
			result.add(combobox);
		}
		List<AccountStatus> statusEnum = EnumUtil.getEnumList(AccountStatus.class);
		for(AccountStatus status:statusEnum) {
			result.add(new Combobox(String.valueOf(status.getType()),status.getAccountStatus()));
		}
		return result;
	}

}
